package com.FH.organization.departmentCrp;

import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by ygg on 2016/6/28.
 *
 * 部门资源类
 *
 */

@Path("/departmentCrp")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class DepartmentCrpResource {

    @EJB
    private DepartmentCrpDAO departmentDAO;


    /**
     * 按条件查询会员列表
     * @param search
     * @param page
     * @param size
     * @return
     */
    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getDepartmentInfo(@PathParam("search") String search, @PathParam("page") String page, @PathParam("size") String size){
        //添加分页查询
        if(null==page||"".equals(page)||"0".equals(page))
        {
            page = "1";	//默认从第1页开始查起
        }/*else
        {
            page =((Integer.parseInt(page)-1)*Integer.parseInt(size))+"";
        }*/
        if(null==size||"".equals(size))
        {
            size = "10";//默认10行数据
        }
        return departmentDAO.getDepartmentInfo(search,page,size);
    }

    @POST
    @Path("/addOrg")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addDepartmentInfo(String str){
        return departmentDAO.addDepartmentInfo(str);
    }

    /**
     * 删除部门方法
     * @param str
     * @return
     */
    @PUT
    @Path("/delete")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteDepartmentTypeInfo(String str){

        return departmentDAO.deleteDepartmentInfo(str);
    }

    @PUT
    @Path("/update")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateDepartmentTypeInfo(String str){

        return departmentDAO.updateDepartmentInfo(str);
    }

    @POST
    @Path("/addOrgUpdate")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addOrUpdateDepartmentInfo(DepartmentCrpPullDTO departmentPullDTO){
        return departmentDAO.addMhDepartmentInfo(departmentPullDTO);
    }


    @PUT
    @Path("/mhdelete")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteMhDepartmentTypeInfo(DepartmentCrpPullDTO departmentPullDTO){

        return departmentDAO.deleteMhDepartmentInfo(departmentPullDTO);
    }

    @PUT
    @Path("/mhupdate")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateMhDepartmentTypeInfo(DepartmentCrpPullDTO departmentPullDTO){

        return departmentDAO.updateMhDepartmentInfo(departmentPullDTO);
    }

    @POST
    @Path("/updateFromBase")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateDepartmentFromBase(){
        return departmentDAO.updateDepartmentFromBase();
    }
}
